import { Controller } from "../../mvc/core/Controller";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ECmdCoreCommand } from "../../../Message/Command/ECmdCoreCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { LayerManager } from "../manager/LayerManager";
import { EffectPlayer } from "../scene/player/item/EffectPlayer";
import { Global } from "../../../com/gengine/global/Global";
import { StaticResUrl } from "../resource/StaticResUrl";
import { ModelType } from "../scene/modle/data/ModelType";
import { DataEvent } from "../events/DataEvent";
import { GameRMI } from "../net/rmi/GameRMI";
import { Alert } from "../../../com/mui/controls/Alert";
import { Language } from "../../../extend/language/Language";
import { BrowerManager } from "../../../com/gengine/manager/BrowerManager";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SAttribute } from "../../../Message/Public/SAttribute";
import { EKickOutReason } from "../../../Message/Public/EKickOutReason";
import { IssmNoticItem } from "../view/msgbroad/IssmNoticItem";
import { MsgManager } from "../manager/MsgManager";
import { ParamsConst } from "../../common/global/ParamsConst";
import { BrowerUtil } from "../../../com/gengine/utils/BrowerUtil";
import { KillUserView } from "../view/common/KillUserView";
type int = number;
//class SystemController
    
    export  class SystemController extends Controller
    {
       

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ECmdCoreCommand._ECmdCoreKillUser, this.onKillUserHandler);
            Dispatcher.addEventListener(EventName.SocketClose, this.onSockCloseHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdateHandler);
            return;
        }

        /* internal  */onRoleLevelUpdateHandler(arg1: PlayerEvent): void
        {
            if (this._levelUp) 
            {
                if (LayerManager.highestLayer.contains(this._levelUp)) 
                {
                    LayerManager.highestLayer.removeChild(this._levelUp);
                }
                this._levelUp.stop();
            }
            else 
            {
                this._levelUp = new EffectPlayer();
                this._levelUp.playTotal = 1;
            }
            if (LayerManager.highestLayer.contains(this._levelUp) == false) 
            {
                LayerManager.highestLayer.addChild(this._levelUp);
            }
            this._levelUp.move(Global.stage.stageWidth / 2, Global.stage.stageHeight / 2 - 160);
            this._levelUp.load(StaticResUrl.Levelup1, ModelType.Effect, null);
            return;
        }

        /* internal  */onSockCloseHandler(arg1: DataEvent): void
        {
            if (this._SockCloseTimeOut <= 0) 
            {
                this._SockCloseTimeOut = flash.utils.setTimeout(this.socketClose, 12000);
            }
            return;
        }

        /* internal  */socketClose(): void
        {
            if (GameRMI.instance.isConnected == false) 
            {
                if (this._alert == null) 
                {
                    Alert.timerNO = false;
                    Alert.mode = Alert.Mode_Simple;
                    this._alert = Alert.show(Language.getString(10012), null, Alert.OK, null, this.onCloseHandler);
                }
            }
            this._SockCloseTimeOut = 0;
            return;
        }

        /* internal  */onCloseHandler(arg1: int): void
        {
            this._alert = null;
            if (arg1 == Alert.OK) 
            {
                BrowerManager.instance.reload();
            }
            return;
        }

        /* internal  */onKillUserHandler(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc1=arg1.messageBase as SAttribute;
            var loc5=loc1.value;
            switch (loc5) 
            {
                case EKickOutReason._EKickOutReasonByLockPlayer:
                {
                    this.alert(Language.getString(10004));
                    break;
                }
                case EKickOutReason._EKickOutReasonByGMOperation:
                {
                    this.alert(Language.getString(10013));
                    break;
                }
                case EKickOutReason._EKickOutReasonByErrorVersion:
                {
                    this.alert(Language.getString(10005));
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseGate:
                {
                    this.showKillView(EKickOutReason._EKickOutReasonByCloseGate);
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseCell:
                {
                    this.showKillView(EKickOutReason._EKickOutReasonByCloseCell);
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseGateMgr:
                {
                    this.showKillView(EKickOutReason._EKickOutReasonByCloseGateMgr);
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseInterMgr:
                {
                    this.showKillView(EKickOutReason._EKickOutReasonByCloseInterMgr);
                    break;
                }
                case EKickOutReason._EKickOutReasonByCloseDbApp:
                {
                    this.showKillView(EKickOutReason._EKickOutReasonByCloseDbApp);
                    break;
                }
                case EKickOutReason._EKickOutReasonByElseLogin:
                {
                    this.showKillView(EKickOutReason._EKickOutReasonByElseLogin);
                    break;
                }
                case EKickOutReason._EKickOutReasonByDbUpdateFail:
                {
                    this.showKillView(EKickOutReason._EKickOutReasonByDbUpdateFail);
                    break;
                }
                case EKickOutReason._EKickOutReasonByIssmThreeHour:
                {
                    loc3 = Language.getString(10010);
                    this.alert1(loc3);
                    loc2 = new IssmNoticItem();
                    loc2.updateData(loc3);
                    MsgManager._msgIssmImpl.addItem(loc2);
                    break;
                }
                case EKickOutReason._EKickOutReasonByIssmOfflineTimeLessFiveHour:
                {
                    loc4 = Language.getString(10011);
                    this.alert1(loc4);
                    loc2 = new IssmNoticItem();
                    loc2.updateData(loc4);
                    MsgManager._msgIssmImpl.addItem(loc2);
                    break;
                }
            }
            return;
        }

        /* internal  */alert1(arg1: string, arg2: uint=4): void
        {
            if (this._killUserView != null) 
            {
                return;
            }
            if (this._alert == null) 
            {
                Alert.mode = Alert.Mode_Simple;
                this._alert = Alert.show(arg1, null, arg2, Global.stage as Object /* flash.display.Sprite */, this.closeHandler1);
            }
            return;
        }

        /* internal  */closeHandler1(arg1: int): void
        {
            this._alert = null;
            if (arg1 == Alert.OK) 
            {
                if (!(ParamsConst.instance.proctecUrl == null) && !(ParamsConst.instance.proctecUrl == "")) 
                {
                    BrowerUtil.getUrl(ParamsConst.instance.proctecUrl, "_self");
                }
                else if (!(ParamsConst.instance.actimUrl == null) && !(ParamsConst.instance.actimUrl == "")) 
                {
                    BrowerManager.instance.getUrl(ParamsConst.instance.actimUrl);
                }
            }
            return;
        }

        /* internal  */alert(arg1: string, arg2: uint=4): void
        {
            if (this._killUserView != null) 
            {
                return;
            }
            if (this._alert == null) 
            {
                Alert.mode = Alert.Mode_Simple;
                this._alert = Alert.show(arg1, null, arg2, Global.stage as Object /* flash.display.Sprite */, this.closeHandler);
            }
            return;
        }

        /* internal  */closeHandler(arg1: int): void
        {
            this._alert = null;
            if (arg1 == Alert.OK) 
            {
                if (!(ParamsConst.instance.actimUrl == null) && !(ParamsConst.instance.actimUrl == "")) 
                {
                    BrowerManager.instance.getUrl(ParamsConst.instance.actimUrl);
                }
            }
            return;
        }

        /* internal  */showKillView(arg1: int): void
        {
            if (this._alert != null) 
            {
                return;
            }
            if (this._killUserView == null) 
            {
                this._killUserView = new KillUserView();
            }
            this._killUserView.updateContentByType(arg1);
            this._killUserView.show();
            return;
        }

        private /* var */_alert: Object /* flash.display.Sprite */;

        private /* var */_killUserView: KillUserView;

        private /* var */_levelUp: EffectPlayer;

        private /* var */_SockCloseTimeOut: uint;
    }
